package com.ant.storage.controller;


import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.CashbookDto;
import com.ant.storage.pojo.Cashbook;
import com.ant.storage.service.ICashbookService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author melon
 * @since 2023-11-09
 */
@RestController
@RequestMapping("/cashbook")
public class CashbookController {

    @Autowired
    private ICashbookService cashbookService;

    @ApiOperation(value = "获取出入记录列表")
    @GetMapping("/getCashbookList")
    public ResultPage getCashbookList(CashbookDto dto) {
        return ResultPage.success("获取成功", cashbookService.queryList(dto));
    }

    @ApiOperation(value = "获取物品库存数据列表")
    @PostMapping("/save")
    public ResultVo save(@RequestBody  Cashbook cashbook) {
        return cashbookService.saveCashbook(cashbook);
    }


    @ApiOperation(value = "获取物品库存数据列表")
    @PostMapping("/saveBatchs")
    public ResultVo saveBatchs(@RequestBody List<Cashbook> cashbook) {
        return cashbookService.saveBatchs(cashbook);
    }


    @ApiOperation(value = "结存")
    @PostMapping("/balance")
    public ResultVo balance() {
        return cashbookService.balance();
    }


    @ApiOperation(value = "自动结存")
    @PostMapping("/automaticBalance")
    public ResultVo automaticBalance() {
        return cashbookService.automaticBalance();
    }


    @ApiOperation(value = "结存")
    @GetMapping("/getBalance/{id}")
    public ResultVo getBalance(@PathVariable(value = "id", required = false) String id, HttpServletRequest request) {
        String str = cashbookService.getBalance(id,request);
        return  ResultVo.success("操作成功",str);
    }


    @ApiOperation(value = "通过id 获取记账明细")
    @GetMapping("/getBalanceId/{id}")
    public ResultVo getBalanceId(@PathVariable(value = "id", required = false) Integer id) {
        return  ResultVo.success("操作成功",cashbookService.getBalanceId(id));
    }

    @ApiOperation(value = "通过id 获取记账明细")
    @GetMapping("/getBalanceIds")
    public ResultVo getBalanceIds(@RequestParam("ids")  String ids) {
        return  ResultVo.success("操作成功",cashbookService.getBalanceIds(ids));
    }





}
